package com.probiz.estoresa.solrsearch.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.core.controller.BaseController;
import com.probiz.estore.solrsearch.service.SolrSearchService;


public class SolrIndexController extends BaseController {
    private SolrSearchService solrSearchService;
	
	public void setSolrSearchService(SolrSearchService solrSearchService) {
		this.solrSearchService = solrSearchService;
	}
	public ModelAndView defaultAction(HttpServletRequest request,HttpServletResponse response){
		return new ModelAndView("tool/solrIndexMgr");	
    } 
    /**
     * 重建索引
     * @param request
     * @param response
     * @return
     */
	public ModelAndView rebuildIndex(HttpServletRequest request,HttpServletResponse response){
       int resultCode= solrSearchService.buildFullIndex();
       if(resultCode == HttpServletResponse.SC_OK){
    	   saveMessage(request, getMessage("solrIndexDetail.rebuildIndex.success"));
       }else{
    	   saveErrorMessage(request, getMessage("solrIndexDetail.rebuildIndex.fail"));
       }
	   return new ModelAndView("tool/solrIndexMgr");	
        
    }
    
    /**
     * 增量更新索引【因在oracle下无法正常执行，本方法暂未起作用】
     * @param request
     * @param response
     * @return
     */
    public ModelAndView updateIndex(HttpServletRequest request,HttpServletResponse response){
        int resultCode= solrSearchService.buildDeltaIndex();
        if(resultCode == HttpServletResponse.SC_OK){
     	   saveMessage(request, getMessage("solrIndexDetail.updateIndex.success"));
        }else{
     	   saveErrorMessage(request, getMessage("solrIndexDetail.updateIndex.fail"));
        } 
        return new ModelAndView("tool/solrIndexMgr");	
        
    }

	
    
}

